package com.example.jn_dxs.Ui.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.jn_dxs.Base.BaseActivity;
import com.example.jn_dxs.Base.BaseViewModel;
import com.example.jn_dxs.Bean.PopuBean;
import com.example.jn_dxs.Bean.WaterLevelBean;
import com.example.jn_dxs.Bean.WaterTemperatureBean;
import com.example.jn_dxs.R;
import com.example.jn_dxs.Ui.adapter.PopuAdapter;
import com.example.jn_dxs.Utlis.PopWindowUtil;
import com.example.jn_dxs.ViewModel.StatisticsVM;
import com.example.jn_dxs.databinding.ActivitySingleWellWaterLevelBinding;

import java.util.ArrayList;
import java.util.List;

public class
SingleWellWaterLevelActivity extends BaseActivity<StatisticsVM, ActivitySingleWellWaterLevelBinding> {

    private View MPopuView;
    private RecyclerView PopuRecyc;
    private PopuAdapter adapter;
    private List<PopuBean> list = new ArrayList<>();

    @Override
    protected int getLayoutId() {
        return R.layout.activity_single_well_water_level;
    }

    @Override
    protected void initEventAndView() {
        binding.MyTopBar.tvBack.setOnClickListener(v -> finish());
        binding.MyTopBar.tvTitle.setText("水位查询");
        binding.MyTopBar.tvRight.setVisibility(View.VISIBLE);
//        binding.MyTopBar.tvRight.setText("辛电11老");
//        binding.MyTopBar.tvRight.setOnClickListener(v -> {
//            PopWindowUtil.getInstance(this).popupCrater(binding.IV, MPopuView, binding.MyTopBar.tvRight);
//        });
//
//        MPopuView = LayoutInflater.from(this).inflate(R.layout.pop_xiangshang_view, null, false);
//        PopuRecyc = MPopuView.findViewById(R.id.tv_record);
//        adapter = new PopuAdapter(R.layout.item_popupview);
//        PopuRecyc.setAdapter(adapter);
//        adapter.setListenter((view, popuBean, pos) -> {
//            binding.MyTopBar.tvRight.setText(popuBean.getName());
//            PopWindowUtil.getInstance(this).setDismiss();
//        });
//
//        for (int i = 0; i < 10; i++) {
//            list.add(new PopuBean("辛电1" + i + "老", i + ""));
//        }
//        adapter.setNewData(list);
        if (!getIntent().getStringExtra("id").isEmpty()) {
            model.getDetail(getIntent().getStringExtra("id"));
            binding.DrillingNumber.setText(getIntent().getStringExtra("id"));
        }
    }

    @Override
    public void initClick() {
        binding.HistoricalStatistics.setOnClickListener(v -> {
            startActivity(new Intent(this, WaterLevelStatisticsActivity.class).putExtra("id", getIntent().getStringExtra("id")));
        });
    }
    @Override
    protected void onObjectDataChange(JSONObject object) {
        super.onObjectDataChange(object);
        JSONObject dtgcjbqkList = object.getJSONObject("dtgcjbqkList");
        JSONArray sweis = object.getJSONArray("sweis"); //位
        JSONArray swens = object.getJSONArray("swens");  //温
        JSONArray szs = object.getJSONArray("szs");

        if (dtgcjbqkList != null) {
            binding.MyTopBar.tvRight.setText( dtgcjbqkList.getString("pkiaa"));//编号
            binding.GeographicLocation.setText(dtgcjbqkList.getString("tkalb"));  //位置
            binding.Longitude.setText(dtgcjbqkList.getString("chahba"));  //经度
            binding.Dimension.setText(dtgcjbqkList.getString("chahbb"));  //维度
            binding.DrillingDepth.setText(dtgcjbqkList.getString("tkcbcl")); //钻孔深度(成井深度)
            binding.OrificeElevation.setText(dtgcjbqkList.getString("tkcah")); //孔口标高(地面高程)

        }
        if (!sweis.isEmpty() && sweis.size() > 0) {
            WaterLevelBean waterLevelBean = JSON.parseObject(sweis.getJSONObject(sweis.size()-1).toJSONString(), WaterLevelBean.class);
            binding.ObservationTime.setText(waterLevelBean.getEndjcsj());
            binding.HighWaterLevel.setText(waterLevelBean.getShuiwei() + "m");
        }
    }

}
